﻿Namespace Security
    Public Class Manager
#Region " Events "
        Public Shared Event Updated(ByVal group As Entities.SecurityGroup)
        Public Shared Event UpdatedGUI(ByVal group As Entities.SecurityGroup)
        Friend Shared Sub OnUpdated(ByVal group As Entities.SecurityGroup)
            RaiseEvent Updated(group)
            Framework.Threading.Invoke(AddressOf OnUpdated_Callback, group)
        End Sub
        Private Shared Sub OnUpdated_Callback(ByVal group As Entities.SecurityGroup)
            RaiseEvent UpdatedGUI(group)
        End Sub
#End Region

        Public Shared Function GetByTypeAndSubType(ByVal type As Entities.SecurityGroupType, ByVal subType As Entities.SecurityGroupSubType) As Entities.SecurityGroup
            Return Handler.GetByTypeAndSubType(type, subType)
        End Function
        Public Shared Function GetAll() As Generic.List(Of Entities.SecurityGroup)
            Return Handler.GetAll
        End Function
        Public Shared Function GetAllByIds(ByVal ids As Generic.HashSet(Of Integer)) As Generic.List(Of Entities.SecurityGroup)
            Return Handler.GetAllByIds(ids)
        End Function
        Public Shared Sub SetupSystemGroups()
            Handler.SetupSystemGroups()
        End Sub


        Public Shared Sub ManageGroups(ByVal owner As Form)
            Dim clsOpts As New Framework.Security.SelectGroupOptions
            clsOpts.Caption = "Manage Security Groups"
            clsOpts.MultiSelect = False
            clsOpts.NewAvailable = True
            Dim clsView As New FSelectSecurityGroups
            clsView.Show(owner, clsOpts)
        End Sub
        Public Shared Function SelectGroups(ByVal owner As Form, ByVal options As SelectGroupOptions) As Generic.List(Of Entities.SecurityGroup)
            Dim clsView As New FSelectSecurityGroups
            Return clsView.ShowDialog(owner, options)
        End Function
        Public Shared Function EditGroup(ByVal owner As Form, ByVal group As Entities.SecurityGroup, ByVal options As EditGroupOptions) As DialogResult
            Dim clsView As New FEditSecurityGroup
            Return clsView.ShowDialog(owner, group, options)
        End Function
    End Class

    Public Class SelectGroupOptions
        Public NewAvailable As Boolean = True
        Public MultiSelect As Boolean = True
        Public Caption As String
        Public HideSecurityGroupIds As New Generic.HashSet(Of Integer)
    End Class
    Public Class EditGroupOptions
        Public EditMembersAvailable As Boolean = False
        Public Caption As String
    End Class
End Namespace
